import Ember from 'ember';
import BaseBusiness from '../base-business';
import Pagination from '../pagination';

export default BaseBusiness.extend(Pagination,{
  header_title:'护理组列表',
  model() {
    return {};
  },
  buildQueryParams:function(){
    var params=this.pagiParamsSet();
    var curController = this.getCurrentController();
    var filter={};
    var sort;
    params.filter = filter;
    sort = {
        remark: 'asc'
    };
    params.sort = sort;
    return params;
  },
  doQuery:function(){
    var _self=this;
    var params=this.buildQueryParams();
    var nurseGroupList=this.findPaged('nursegroup',params,function(nurseGroupList){
      nurseGroupList.forEach(
        function(nurseGroup){
          _self.getStaffByNurseGroup(nurseGroup);
          return nurseGroup;
        }
      );
    });
    this.getCurrentController().set("nurseGroupList", nurseGroupList);

  },
  actions:{
    search:function(){
      this.doQuery();
    },
  },
  getStaffByNurseGroup: function(nurseGroup){

    this.store.query('user',{filter:{nurseGroup:{id:nurseGroup.id}}}).then(function(allStaffList){
      var s='';
      allStaffList.forEach(function(staff){

        s +=  staff.get("name")+'，';

      });
      nurseGroup.set('member',s.substring(0,s.length-1));
    });
    // this.store.query('room',{filter:{nurseGroup:{id:nurseGroup.id}}}).then(function(allRoomList){
    //   var r='';
    //   allRoomList.forEach(function(room){
    //     r += room.get('name')+' ';
    //   });
    //   nurseGroup.set('roomsName',r);
    // });
  },
  setupController: function(controller,model){
    this.doQuery();
    this._super(controller,model);

  }
});
